package com.employeemanage.controller;

import com.employeemanage.domain.resp.PageResult;
import com.employeemanage.domain.resp.Result;
import com.employeemanage.domain.vo.BatchScheduleResponseVo;
import com.employeemanage.domain.vo.BatchScheduleVo;
import com.employeemanage.domain.vo.EmployeeScheduleListVo;
import com.employeemanage.domain.vo.EmployeeScheduleResponseVo;
import com.employeemanage.service.TblEmployeeScheduleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 员工排班表 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-07-05
 */
@RestController
@RequestMapping("/employee/schedule")
@Api(tags = "员工排班管理")
public class TblEmployeeScheduleController {

    @Autowired
    private TblEmployeeScheduleService employeeScheduleService;

    /**
     * 获取员工排班列表
     * @param vo 查询条件
     * @return 分页结果
     */
    @PostMapping("/list")
    @ApiOperation("获取员工排班列表")
    public Result<PageResult<EmployeeScheduleResponseVo>> getEmployeeScheduleList(
            @ApiParam("查询条件") @RequestBody EmployeeScheduleListVo vo) {
        try {
            PageResult<EmployeeScheduleResponseVo> result = employeeScheduleService.getEmployeeScheduleList(vo);
            return Result.success(result);
        } catch (Exception e) {
            return Result.fail("获取员工排班列表失败: " + e.getMessage());
        }
    }

    /**
     * 批量排班
     * @param vo 批量排班请求
     * @return 批量排班结果
     */
    @PostMapping("/batch")
    @ApiOperation("批量排班")
    public Result<BatchScheduleResponseVo> batchSchedule(
            @ApiParam("批量排班请求") @RequestBody BatchScheduleVo vo) {
        try {
            BatchScheduleResponseVo result = employeeScheduleService.batchSchedule(vo);
            return Result.success(result);
        } catch (Exception e) {
            return Result.fail("批量排班失败: " + e.getMessage());
        }
    }

    /**
     * 删除排班
     * @param id 排班编号
     * @return 操作结果
     */
    @DeleteMapping("/delete")
    @ApiOperation("删除排班")
    public Result<Void> deleteSchedule(
            @ApiParam("排班编号") @RequestParam Long id) {
        try {
            boolean success = employeeScheduleService.deleteSchedule(id);
            if (success) {
                return Result.success();
            } else {
                return Result.fail("删除排班失败");
            }
        } catch (Exception e) {
            return Result.fail("删除排班失败: " + e.getMessage());
        }
    }
}
